﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Yupload
{
    class VideoControl
    {
        private Button DeleteVideo { get; set; }
        private TextBox SelectedVideo { get; set; }
        private List<VideoControl> Videos { get; set; }
        private Panel TargetPanel { get; set; }
        private Button AddButton { get; set; }

        public VideoControl(List<VideoControl> videos, Panel targetPanel, Button addButton, string btnText, string dialogueTitle, int index)
        {
            TargetPanel = targetPanel;
            Videos = videos;
            AddButton = addButton;

            OpenFileDialog chooseFile = ChooseFile(dialogueTitle);
            if (chooseFile.ShowDialog() == DialogResult.OK)
            {
                string filePath = chooseFile.FileName;
                SelectedVideo = new TextBox();
                SelectedVideo.Height = 25;
                SelectedVideo.Width = 300;
                SelectedVideo.Top = index >= 1 ? 25 * index + 3 : 3;
                SelectedVideo.Left = 3;
                SelectedVideo.Text = filePath;
                SelectedVideo.Enabled = false;

                DeleteVideo = new Button();
                DeleteVideo.Text = btnText;
                DeleteVideo.Width = 75;
                DeleteVideo.Height = 23;
                DeleteVideo.Top = index >= 1 ? 25 * index + 2 : 2;
                DeleteVideo.Left = SelectedVideo.Width + SelectedVideo.Left + 3;
                DeleteVideo.Click += new EventHandler(DeleteVideo_Click);

                AddButton.Top += 25;

                TargetPanel.Controls.Add(SelectedVideo);
                TargetPanel.Controls.Add(DeleteVideo);

                Videos.Add(this);
            }
        }

        void DeleteVideo_Click(object sender, EventArgs e)
        {
            Videos.Remove(this);
            TargetPanel.Controls.Remove(this.DeleteVideo);
            TargetPanel.Controls.Remove(this.SelectedVideo);
            AddButton.Top -= 25;
        }

        private OpenFileDialog ChooseFile(string dialogueTitle)
        {
            OpenFileDialog chooseFile = new OpenFileDialog();
            chooseFile.Title = dialogueTitle;
            // TODO: Add Filter to Dialog
            chooseFile.InitialDirectory = Application.StartupPath;
            return chooseFile;
        }
    }
}
